﻿using DelonixRegia.Classes;
using DelonixRegia.Classes.RoomRecords;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DelonixRegia
{
    public partial class FindGuest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbxGuestContactNo.Text))
            {
                Classes.RoomBooking rb = RoomRecordsDBManager.GetGuestByContactNo(tbxGuestContactNo.Text);

                if (rb.contactNo != null)
                {
                    lblGuestID.Text = rb.bookingID.ToString();
                    lblGuestFirstName.Text = rb.firstName.ToString();
                    lblGuestLastName.Text = rb.lastName.ToString();
                    lblGuestAdultNo.Text = rb.noOfAdults.ToString();
                    lblGuestChildrenNo.Text = rb.noOfChildren.ToString();
                    lblGuestContactNumber.Text = rb.contactNo.ToString();
                    lblGuestEmailAddress.Text = rb.emailAddress.ToString();
                    lblGuestHomeAddress.Text = rb.address.ToString();
                    lblGuestRoomNumber.Text = rb.roomNo.ToString();

                    lblGuestCardholderName.Text = rb.paymentDetails.cardholderName.ToString();
                    lblGuestCardType.Text = rb.paymentDetails.cardType.ToString();
                    lblGuestCardNumber.Text = rb.paymentDetails.cardNo.ToString();
                    lblGuestExpiryDate.Text = rb.paymentDetails.expiryDate.ToString();
                    lblGuestSecurityCode.Text = rb.paymentDetails.securityCode.ToString();
                    lblGuestPaymentID.Text = rb.paymentDetails.paymentID.ToString();

                    pnlFirstStep.Visible = false;
                    pnlSecondStep.Visible = true;
                    Page.ClientScript.RegisterStartupScript(GetType(), "transitionToSecondStep", "transitionToSecondStep();", true);
                }
                else
                {
                    ClientScriptMgr.showErrorBox("The Guest Information you entered is not available or does not exist!");
                }
            }

            else if (!string.IsNullOrEmpty(tbxGuestName.Text))
            {
                Classes.RoomBooking rbb = RoomRecordsDBManager.GetGuestByName(tbxGuestName.Text);

                if (rbb.contactNo != null)
                {
                    lblGuestID.Text = rbb.bookingID.ToString();
                    lblGuestFirstName.Text = rbb.firstName.ToString();
                    lblGuestLastName.Text = rbb.lastName.ToString();
                    lblGuestAdultNo.Text = rbb.noOfAdults.ToString();
                    lblGuestChildrenNo.Text = rbb.noOfChildren.ToString();
                    lblGuestContactNumber.Text = rbb.contactNo.ToString();
                    lblGuestEmailAddress.Text = rbb.emailAddress.ToString();
                    lblGuestHomeAddress.Text = rbb.address.ToString();
                    lblGuestRoomNumber.Text = rbb.roomNo.ToString();

                    lblGuestCardholderName.Text = rbb.paymentDetails.cardholderName.ToString();
                    lblGuestCardType.Text = rbb.paymentDetails.cardType.ToString();
                    lblGuestCardNumber.Text = rbb.paymentDetails.cardNo.ToString();
                    lblGuestExpiryDate.Text = rbb.paymentDetails.expiryDate.ToString();
                    lblGuestSecurityCode.Text = rbb.paymentDetails.securityCode.ToString();
                    lblGuestPaymentID.Text = rbb.paymentDetails.paymentID.ToString();

                    pnlFirstStep.Visible = false;
                    pnlSecondStep.Visible = true;
                    Page.ClientScript.RegisterStartupScript(GetType(), "transitionToSecondStep", "transitionToSecondStep();", true);
                }
                else
                {
                    ClientScriptMgr.showErrorBox("The Guest Information you entered is not available or does not exist!");
                }
            }
            else
            {
                ClientScriptMgr.showErrorBox("Please enter the following Guest Information!");
            }
        }

        protected void btnEditGuest_Click(object sender, EventArgs e)
        {
            Session["id"] = lblGuestID.Text;
            Session["firstname"] = lblGuestFirstName.Text;
            Session["lastname"] = lblGuestLastName.Text;
            Session["adultno"] = lblGuestAdultNo.Text;
            Session["childrenno"] = lblGuestChildrenNo.Text;
            Session["contactno"] = lblGuestContactNumber.Text;
            Session["email"] = lblGuestEmailAddress.Text;
            Session["address"] = lblGuestHomeAddress.Text;
            Session["roomno"] = lblGuestRoomNumber.Text;
            Session["cardname"] = lblGuestCardholderName.Text;
            Session["cardtype"] = lblGuestCardType.Text;
            Session["cardno"] = lblGuestCardNumber.Text;
            Session["expiry"] = lblGuestExpiryDate.Text;
            Session["csc"] = lblGuestSecurityCode.Text;
            Session["paymentid"] = lblGuestPaymentID.Text;
            Response.Redirect("ModifyGuestRecord.aspx");
        }

        protected void btnGoBackPanel2_Click(object sender, EventArgs e)
        {
            tbxGuestContactNo.Text = "";
            tbxGuestName.Text = "";
            pnlSecondStep.Visible = false;
            pnlFirstStep.Visible = true;
            Page.ClientScript.RegisterStartupScript(GetType(), "transitionToFirstStep", "transitionToFirstStep();", true);
        }
    }
}